﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    class Zig1:Shape
    {
        public Zig1(Point first, Point second, Point third, Point fourth)
            : base(first, second, third, fourth)
        {
        }
        public override void Rotate(Func<int, int, int> IsPosFree)
        {
            switch (Pos)
            {
                case 0:
                    {
                        if (IsPosFree(_coordinates[1].x - 1, _coordinates[1].y + 1) == 0 & IsPosFree(_coordinates[3].x - 1, _coordinates[3].y - 1) == 0 & IsPosFree(_coordinates[4].x, _coordinates[4].y - 2) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].x--;
                            _coordinates[1].y++;
                            _coordinates[3].x--;
                            _coordinates[3].y--;
                            _coordinates[4].y = _coordinates[4].y - 2;
                            Pos = 1;
                        }
                        break;
                    }
                case 1:
                    {
                        if (IsPosFree(_coordinates[1].x + 1, _coordinates[1].y - 1) == 0 & IsPosFree(_coordinates[3].x + 1, _coordinates[3].y + 1) == 0 & IsPosFree(_coordinates[4].x, _coordinates[4].y + 2) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].x++;
                            _coordinates[1].y--;
                            _coordinates[3].x++;
                            _coordinates[3].y++;
                            _coordinates[4].y = _coordinates[4].y + 2;
                            Pos = 0;
                        }
                        break;
                    }
            }
        }
    }
}
